package com.ruoyi.web.controller.actualmaterial;

import java.util.List;

import com.ruoyi.domain.ConstructionRecording;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ActualMaterial;
import com.ruoyi.service.IActualMaterialService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实际用料Controller
 * 
 * @author ruoyi
 * @date 2020-07-22
 */
@Controller
@RequestMapping("/ruoyi/material")
public class ActualMaterialController extends BaseController
{
    private String prefix = "ruoyi/material";

    @Autowired
    private IActualMaterialService actualMaterialService;

    @RequiresPermissions("ruoyi:material:view")
    @GetMapping()
    public String material()
    {
        return prefix + "/material";
    }

    /**
     * 查询实际用料列表
     */
    @RequiresPermissions("ruoyi:material:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ActualMaterial actualMaterial)
    {
        startPage();
        List<ActualMaterial> list = actualMaterialService.selectActualMaterialList(actualMaterial);
        return getDataTable(list);
    }
    /**
     * 查询总项目下对应的实际用料列表
     */
    @RequiresPermissions("ruoyi:material:list")
    @PostMapping("/sId")
    @ResponseBody
    public TableDataInfo sId(Long sId)
    {
        startPage();
//        ConstructionRecording constructionRecording=new ConstructionRecording();
//        long b=constructionRecording.getcPid();
//        String names=constructionRecording.getcTname();
//        long num=constructionRecording.getcTnum();
//        actualMaterial.setcCid(b);
//        actualMaterial.setcPname(names);
//        actualMaterial.setcPnum(num);
        List<ActualMaterial> list = actualMaterialService.selectActualMaterialLists(sId);

        return getDataTable(list);
    }

    /**
     * 导出实际用料列表
     */
    @RequiresPermissions("ruoyi:material:export")
    @Log(title = "实际用料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ActualMaterial actualMaterial)
    {
        List<ActualMaterial> list = actualMaterialService.selectall(actualMaterial);
        ExcelUtil<ActualMaterial> util = new ExcelUtil<ActualMaterial>(ActualMaterial.class);
        return util.exportExcel(list, "实际用料");
    }

    /**
     * 新增实际用料
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存实际用料
     */
    @RequiresPermissions("ruoyi:material:add")
    @Log(title = "实际用料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActualMaterial actualMaterial)
    {
        return toAjax(actualMaterialService.insertActualMaterial(actualMaterial));
    }

    /**
     * 修改实际用料
     */
    @GetMapping("/edit/{cPid}")
    public String edit(@PathVariable("cPid") Long cPid, ModelMap mmap)
    {
        ActualMaterial actualMaterial = actualMaterialService.selectActualMaterialById(cPid);
        mmap.put("actualMaterial", actualMaterial);
        return prefix + "/edit";
    }

    /**
     * 修改保存实际用料
     */
    @RequiresPermissions("ruoyi:material:edit")
    @Log(title = "实际用料", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ActualMaterial actualMaterial)
    {
        return toAjax(actualMaterialService.updateActualMaterial(actualMaterial));
    }

    /**
     * 删除实际用料
     */
    @RequiresPermissions("ruoyi:material:remove")
    @Log(title = "实际用料", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(actualMaterialService.deleteActualMaterialByIds(ids));
    }
}
